import { ArgumentMetadata, HttpException, HttpStatus, Injectable, PipeTransform } from '@nestjs/common';


function validateEmail(email: string) {
    var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
    return emailRegex.test(email);
}

@Injectable()
export class EmailPipe implements PipeTransform {
    transform(value: string, metadata: ArgumentMetadata) {
        console.log(value, metadata, 1111);
        if (validateEmail(value)) return value;
        throw new HttpException('邮箱格式不正确', HttpStatus.BAD_REQUEST)

    }
}
